/**
    Copyright (c) 2010 ATTi 
    All rights reserved.
    Author: Michael Shu
    Date: 8/3/2010
*/

trigger OppForNatSales on Opportunity (before insert, before update, after insert) 
{
    if(trigger.isBefore)
    {
        if(trigger.isInsert)
        {
            OppForNatSalesHelperClass.setIsInsert(true);
        }
        if(trigger.isUpdate){
            if(!OppForNatSalesHelperClass.getIsInsert() && !FollowUpOppHelper.gethaslineItem())
            {
                OppForNatSalesHelperClass.checkOppProduct(trigger.new, trigger.oldMap);
            }       
        }
    }
    else if(trigger.isAfter)
    {
        system.debug('testupdate1');//change by naidu
        //ID AASRecordTypeID = RecordTypeHelper.GetRecordTypeID('Opportunity', 'Advanced Ad Solutions');
        Schema.DescribeSObjectResult d = Schema.SObjectType.Opportunity;
        ID AASRecordTypeID= d.getRecordTypeInfosByName().get('Advanced Ad Solutions').getRecordTypeId();
//end of change
        if(trigger.isInsert)
        {
            
            
            ID NaSaLOppRecordTypeID = OppForNatSalesHelperClass.getOppContractRecordTypeID();
            if(trigger.new.size() == 1)
            {
                system.debug('testupdate2');
                Opportunity o = trigger.new.get(0);
               if((o.RecordTypeId == NaSaLOppRecordTypeID || o.RecordTypeId ==AASRecordTypeID) && o.AccountId != null )
                {
                   system.debug('testupdate3');
                   AccountTeamController acController = new AccountTeamController();
                    acController.oppId = o.Id;
                    acController.addOppTeamsFromParentAccTeams();
                    system.debug('testupdate');
                    
                }
            }               
        }
        
        
    }
}